main(){int v,n,f[10],i,a,b;while(scanf("%d",&v)&&v){scanf("%d",&n);i=10;while(--i)f[i]=0;i=n;while(i--){scanf("%d%d",&a,&b);f[a]+=b;}n=10;do{--n;i+=n*f[n];v-=f[n];}while(n*v>0);printf("%d\n",i+1+v*n);}}
